package adc.budget.impl.hb.dao;

import java.util.Map;

import org.springframework.stereotype.Repository;

import adc.app.impl.jpa.JpaDao;
import adc.app.spec.IBo;
import adc.budget.impl.hb.bo.HbAccount;
import adc.budget.impl.hb.bo.HbAccountType;
import adc.budget.impl.hb.bo.HbBudgetBo;
import adc.budget.impl.hb.bo.HbCategory;
import adc.budget.impl.hb.bo.HbTransaction;
import adc.budget.spec.bo.IAccount;
import adc.budget.spec.bo.IAccountType;
import adc.budget.spec.bo.ICategory;
import adc.budget.spec.bo.ITransaction;

import com.google.common.collect.Maps;

@Repository
public class HbBudgetDao extends JpaDao<IBo> {

    private static final Map<Class<? extends IBo>, Class<? extends HbBudgetBo>> BO_IMPS = Maps.newHashMap();

    static {
        BO_IMPS.put(IAccountType.class, HbAccountType.class);
        BO_IMPS.put(IAccount.class, HbAccount.class);
        BO_IMPS.put(ICategory.class, HbCategory.class);
        BO_IMPS.put(ITransaction.class, HbTransaction.class);
    }

    @SuppressWarnings("unchecked")
    protected <X extends IBo, R extends X> Class<R> implClass(Class<X> specClass) {
        if (!BO_IMPS.containsKey(specClass)) {
            throw new IllegalArgumentException(specClass.getName() + " is not an entity class");
        }
        return (Class<R>) BO_IMPS.get(specClass);

    }
}
